package de.hsma.srn.view.components;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.JList;

public class List extends JList {
	/**
	 * UID
	 */
	private static final long serialVersionUID = 1L;

	public List() {
		super();
		initialize();
		initializeListeners();
	}
	
	/**
	 * Return the selected Value as string or null if value is not of type String
	 */
	public String getSelectedValue() {
		Object obj = super.getSelectedValue();
		if(obj instanceof String) {
			return (String) obj;
		}
		return null;
	}
	
	public List(String[] data) {
		super(data);
		initialize();
	}
	
	private void initialize() {
		setFont(new Font("Helvetica", Font.PLAIN, 12));
		setBorder(null);
		this.setForeground(new Color(140, 180, 204));
		this.setBackground(new Color(255, 255, 255));
	}
	private void initializeListeners() {
		addFocusListener(new FocusListener() {

			@Override
			public void focusGained(FocusEvent arg0) {
				setForeground(new Color(0, 0, 0));
				setBackground(new Color(225, 235, 242));
			}

			@Override
			public void focusLost(FocusEvent arg0) {
				setForeground(new Color(140, 180, 204));
				setBackground(new Color(255, 255, 255));
			}
			
		});
	}
}
